<!DOCTYPE html><!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]--><!--[if gt IE 8]><!--><html class="no-js" lang="en"><!--<![endif]--><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title></title>
  

  
  <link href="https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700" rel="stylesheet" type="text/css">

  <link rel="stylesheet" href="/v2/css/theme.css" type="text/css">
  <link href="/v2/css/custom.css" rel="stylesheet">

  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>
  <script src="../../js/theme.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js"></script>
  <script src="../../search/main.js"></script>

  <style>
    body {font-size: 90%;}
    pre, code {font-size: 100%;}
    h3, h4, h5, h6 {color: #2980b9; font-weight: 300}
  </style> 
<meta name="robots" content="noindex"></head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
      <div class="wy-side-nav-search">
        <a href="/v2/" class="icon icon-home"> </a>
        <div role="search">
  <form id="rtd-search-form" class="wy-form" action="" method="get">
    <input type="text" name="q" placeholder="Search docs">
    <input type="hidden" name="check_keywords" value="yes">
    <input type="hidden" name="area" value="default">
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
      <ul class="current">
   
  <span class="toctree-l0">Home</span>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/">Welcome</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/imprint/">Imprint</a>
    
  </li>
     
  <span class="toctree-l0">Articles</span>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/articles/getting-started/">Getting started</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/articles/heroku/">Heroku</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/articles/express/">Usage with Express.JS</a>
    
  </li>
     
  <span class="toctree-l0">Docs</span>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/docs/installation/">Installation</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/docs/usage/">Usage</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/docs/promises/">Promises</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/docs/models/">Models</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/docs/instances/">Instances</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/docs/associations/">Associations</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/docs/hooks/">Hooks</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/docs/transactions/">Transactions</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/docs/migrations/">Migrations</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/docs/misc/">Misc</a>
    
  </li>
     
  <span class="toctree-l0">API</span>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/api/sequelize/">Sequelize</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/api/model/">Model</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/api/instance/">Instance</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/api/associations/">Associations</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/api/hooks/">Hooks</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/api/promise/">Promise</a>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/api/transaction/">Transaction</a>
    
  </li>
  
  <li class="toctree-l1 current">
    <a class="current" href="/v2/api/datatypes/">Datatypes</a>
    
    <ul>
      
    </ul>
    
  </li>
  
  <li class="toctree-l1 ">
    <a class="" href="/v2/api/errors/">Errors</a>
    
  </li>
    
</ul>
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="icon icon-reorder"></i>
        <a href="/v2/"></a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="/v2/">Docs</a> »</li>
    <li>Datatypes</li>
      <li class="wy-breadcrumbs-aside">
        
      </li>
  </ul>
  <hr>
</div>
          <div role="main">
            <div class="section">
              <p><a name="datatypes"></a></p>
<h1 id="class-datatypes">Class DataTypes</h1>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L309">View code</a>
A convenience class holding commonly used data types. The datatypes are used when definining a new model using <code>Sequelize.define</code>, like this:</p>
<pre><code class="language-js">sequelize.define('model', {
  column: DataTypes.INTEGER
})
</code></pre>
<p>When defining a model you can just as easily pass a string as type, but often using the types defined here is beneficial. For example, using <code>DataTypes.BLOB</code>, mean
that that column will be returned as an instance of <code>Buffer</code> when being fetched by sequelize.</p>
<p>Some data types have special properties that can be accessed in order to change the data type. For example, to get an unsigned integer with zerofill you can do <code>DataTypes.INTEGER.UNSIGNED.ZEROFILL</code>.
The order you access the properties in do not matter, so <code>DataTypes.INTEGER.ZEROFILL.UNSIGNED</code> is fine as well. The available properties are listed under each data type.</p>
<p>To provide a length for the data type, you can invoke it like a function: <code>INTEGER(2)</code></p>
<p>Three of the values provided here (<code>NOW</code>, <code>UUIDV1</code> and <code>UUIDV4</code>) are special default values, that should not be used to define types. Instead they are used as shorthands for
defining default values. For example, to get a uuid field with a default value generated following v1 of the UUID standard:</p>
<pre><code class="language-js">sequelize.define('model', {
  uuid: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV1,
    primaryKey: true
  }
})
</code></pre>
<hr>
<p><a name="string"></a></p>
<h2 id="string"><code>STRING</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L317">View code</a>
A variable length string. Default length 255</p>
<p>Available properties: <code>BINARY</code></p>
<hr>
<p><a name="char"></a></p>
<h2 id="char"><code>CHAR</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L325">View code</a>
A fixed length string. Default length 255</p>
<p>Available properties: <code>BINARY</code></p>
<hr>
<p><a name="text"></a></p>
<h2 id="text"><code>TEXT</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L330">View code</a>
An unlimited length text column</p>
<hr>
<p><a name="integer"></a></p>
<h2 id="integer"><code>INTEGER</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L338">View code</a>
A 32 bit integer.</p>
<p>Available properties: <code>UNSIGNED</code>, <code>ZEROFILL</code></p>
<hr>
<p><a name="bigint"></a></p>
<h2 id="bigint"><code>BIGINT</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L346">View code</a>
A 64 bit integer.</p>
<p>Available properties: <code>UNSIGNED</code>, <code>ZEROFILL</code></p>
<hr>
<p><a name="date"></a></p>
<h2 id="date"><code>DATE</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L351">View code</a>
A datetime column</p>
<hr>
<p><a name="dateonly"></a></p>
<h2 id="dateonly"><code>DATEONLY</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L356">View code</a>
A date only column</p>
<hr>
<p><a name="boolean"></a></p>
<h2 id="boolean"><code>BOOLEAN</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L361">View code</a>
A boolean / tinyint column, depending on dialect</p>
<hr>
<p><a name="float"></a></p>
<h2 id="float"><code>FLOAT</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L369">View code</a>
Floating point number. Accepts one or two arguments for precision</p>
<p>Available properties: <code>UNSIGNED</code>, <code>ZEROFILL</code></p>
<hr>
<p><a name="now"></a></p>
<h2 id="now"><code>NOW</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L374">View code</a>
A default value of the current timestamp</p>
<hr>
<p><a name="blob"></a></p>
<h2 id="blob"><code>BLOB</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L380">View code</a>
Binary storage. Available lengths: <code>tiny</code>, <code>medium</code>, <code>long</code></p>
<hr>
<p><a name="decimal"></a></p>
<h2 id="decimal"><code>DECIMAL</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L388">View code</a>
Decimal number. Accepts one or two arguments for precision</p>
<p>Available properties: <code>UNSIGNED</code>, <code>ZEROFILL</code></p>
<hr>
<p><a name="uuid"></a></p>
<h2 id="uuid"><code>UUID</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L393">View code</a>
A column storing a unique univeral identifier. Use with <code>UUIDV1</code> or <code>UUIDV4</code> for default values.</p>
<hr>
<p><a name="uuidv1"></a></p>
<h2 id="uuidv1"><code>UUIDV1</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L398">View code</a>
A default unique universal identifier generated following the UUID v1 standard</p>
<hr>
<p><a name="uuidv4"></a></p>
<h2 id="uuidv4"><code>UUIDV4</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L403">View code</a>
A default unique universal identifier generated following the UUID v2 standard</p>
<hr>
<p><a name="hstore"></a></p>
<h2 id="hstore"><code>HSTORE</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L409">View code</a>
A key / value column. Only available in postgres.</p>
<hr>
<p><a name="virtual"></a></p>
<h2 id="virtual"><code>VIRTUAL</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L449">View code</a>
A virtual value that is not stored in the DB. This could for example be useful if you want to provide a default value in your model
that is returned to the user but not stored in the DB.</p>
<p>You could also use it to validate a value before permuting and storing it. Checking password length before hashing it for example:</p>
<pre><code class="language-js">sequelize.define('user', {
  password_hash: DataTypes.STRING
  password: {
    type: DataTypes.VIRTUAL,
    set: function (val) {
       this.setDataValue('password', val);
       this.setDataValue('password_hash', this.salt + val);
     },
     validate: {
        isLongEnough: function (val) {
          if (val.length &lt; 7) {
            throw new Error("Please choose a longer password")
         }
      }
    }
  }
})
</code></pre>
<p>In the above code the password is stored plainly in the password field so it can be validated, but is never stored in the DB.
<strong>Aliases:</strong> NONE</p>
<hr>
<p><a name="enum"></a></p>
<h2 id="enum"><code>ENUM</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L457">View code</a>
An enumeration. <code>DataTypes.ENUM('value', 'another value')</code>.</p>
<hr>
<p><a name="array"></a></p>
<h2 id="array"><code>ARRAY()</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/5aa77fa291abeaf0498f65724000c75da9ab9028/lib/data-types.js#L477">View code</a>
An array of <code>type</code>, e.g. <code>DataTypes.ARRAY(DataTypes.DECIMAL)</code>. Only available in postgres.</p>
<hr>
<p><em>This document is automatically generated based on source code comments. Please do not edit it directly, as your changes will be ignored. Please write on <a href="/v2/irc://irc.freenode.net/#sequelizejs">IRC</a>, open an issue or a create a pull request if you feel something can be improved. For help on how to write source code documentation see <a href="http://usejsdoc.org">JSDoc</a> and <a href="https://github.com/tj/dox">dox</a></em></p>
            </div>
          </div> 
          <footer>
  

  <hr>

  <div role="contentinfo">
    <p>
    <!-- Copyright etc -->
    </p>
  </div>

  Built with <a href="http://www.mkdocs.org">MkDocs</a>, using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
	  
        </div>
      </div>

    </section>

  </div>

<div class="rst-versions" role="note" style="cursor: pointer">
    <span class="rst-current-version" data-toggle="rst-current-version">
        
      <span><a href="/v2/" style="color: #fcfcfc;">« Previous</a></span>
      <span style="margin-left: 15px"><a href="/v2/" style="color: #fcfcfc">Next »</a></span>
    </span>
</div>

</body></html>